package com.hongning.railway.ui.main.mine;

import android.os.Bundle;
import android.view.View;

import com.hongning.railway.R;
import com.hongning.railway.app.Constant;
import com.hongning.railway.databinding.ActivityAboutBinding;
import com.hongning.railway.ui.widget.alertview.AlertView;
import com.hongning.railway.ui.widget.alertview.AlertViewOnItemClickListener;
import com.hongning.railway.util.Apputils;
import com.hongning.railway.util.DataCleanManager;

import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import me.goldze.mvvmhabit.BR;
import me.goldze.mvvmhabit.base.AppManager;
import me.goldze.mvvmhabit.base.BaseActivity;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.http.BaseResponse;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.goldze.mvvmhabit.utils.SPUtils;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class AboutActivity extends BaseActivity<ActivityAboutBinding, BaseViewModel> {
    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_about;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();

        binding.appTitle.tvTopTitle.setText("关于红宁");
        binding.appTitle.ivLeft.setVisibility(View.VISIBLE);
        binding.appTitle.ivLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        binding.tvCache.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDialog();
            }
        });
        binding.tvVersion.setText(Apputils.getAppVersionName(this));
        try {
            binding.tvCache.setText(DataCleanManager.getTotalCacheSize(AboutActivity.this));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void showDialog(){
        new AlertView("提示", "确定要清除缓存？", "取消", new String[]{"确定"}, null, this, AlertView.Style.Alert, new AlertViewOnItemClickListener() {

            @Override
            public void onItemClick(Object o, int position) {
                if (position == AlertView.CANCELPOSITION) {
                    //点击取消按钮

                }else {
                    DataCleanManager.clearAllCache(AboutActivity.this);
                    try {
                        binding.tvCache.setText(DataCleanManager.getTotalCacheSize(AboutActivity.this));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
//                    showMessage("清除成功");
                    ToastUtils.showShort("清除成功");
                }
            }
        }).show();
    }
}
